package a12_图论;

import java.util.LinkedList;
import java.util.Queue;

/**
 * <p>
 * a04_广度优先搜索理论基础复习1
 * </p>
 *
 * @author flyduck
 * @since 2025/3/11
 */
public class a04_广度优先搜索理论基础复习1 {

    public static void main(String[] args) {

    }

    private int[][] dirs = new int[][]{{0,1},{1,0},{-1,0},{0,-1}};

    private void bfs(int[][] grid,
                     boolean[][] visited,
                     int x,
                     int y){
        Queue<int[]> queue = new LinkedList<>();
        queue.add(new int[]{x,y});
        visited[x][y] = true;

        while (!queue.isEmpty()){
            int[] poll = queue.poll();
            for (int[] dir : dirs) {
                int nextX = poll[0] + dir[0];
                int nextY = poll[1] + dir[1];
                if(nextX >= 0 && nextX < grid.length && nextY >= 0 && nextY < grid[0].length){
                    if(!visited[nextX][nextY]){
                        queue.add(new int[]{nextX,nextY});
                        visited[nextX][nextY] = true;
                    }
                }
            }
        }
    }
}
